package qq2564874169.tuaotuao.fx;

import qq2564874169.tuaotuao.fx.utils.StringUtil;

public class FxAssert {
    public static void isNull(Object obj, RuntimeException e) {
        if (obj == null) {
            return;
        }
        if (e == null) {
            e = new AssertException("必须是空。");
        }
        throw e;
    }

    public static void isNull(Object obj, String message) {
        isNull(obj, new AssertException(message));
    }

    public static void isNull(Object obj) {
        isNull(obj, (RuntimeException) null);
    }

    public static void isNotNull(Object obj, RuntimeException e) {
        if (obj != null) {
            return;
        }
        if (e == null) {
            e = new AssertException("必须有值。");
        }
        throw e;
    }

    public static void isNotNull(Object obj) {
        isNotNull(obj, (RuntimeException) null);
    }

    public static void isNotNull(Object obj, String message) {
        isNotNull(obj, new AssertException(message));
    }

    public static void isNotNull(Object obj, String template, String... args) {
        isNotNull(obj, new AssertException(StringUtil.format(template, (Object[]) args)));
    }

    public static void isEquals(Object expect, Object actual, RuntimeException e) {
        if (expect == null && actual == null) {
            return;
        }
        if (expect != null && actual != null) {
            if (expect instanceof Number && actual instanceof Number && expect.toString().equals(actual.toString())) {
                return;
            }
            if (expect.equals(actual)) {
                return;
            }
        }
        if (e == null) {
            e = new AssertException(expect + " 与 " + actual + " 必须相同。");
        }
        throw e;
    }

    public static void isEquals(Object expect, Object actual) {
        isEquals(expect, actual, (RuntimeException) null);
    }

    public static void isEquals(Object expect, Object actual, String message) {
        isEquals(expect, actual, new AssertException(message));
    }

    public static void isNotEquals(Object expect, Object actual, String message) {
        try {
            isEquals(expect, actual);
        } catch (RuntimeException ex) {
            return;
        }
        if (message == null) {
            message = expect + " 与 " + actual + " 必须不相同。";
        }
        throw new AssertException(message);
    }

    public static void isNotEquals(Object expect, Object actual) {
        isNotEquals(expect, actual, null);
    }

    /**
     * 判断数字大小
     */
    public static void magnitude(Number small, Number big, RuntimeException e) {
        if (small.doubleValue() < big.doubleValue()) {
            return;
        }
        if (e == null) {
            e = new AssertException(small + " 必须小于 " + big + "。");
        }
        throw e;
    }

    /**
     * 判断数字大小
     */
    public static void magnitude(Number small, Number big, String message) {
        magnitude(small, big, new RuntimeException(message));
    }

    public static void isTrue(boolean b, RuntimeException e) {
        if (b == true) {
            return;
        }
        if (e == null) {
            e = new AssertException("必须是TRUE。");
        }
        throw e;
    }

    public static void isTrue(boolean b, String message) {
        isTrue(b, new AssertException(message));
    }

    public static void isTrue(boolean b) {
        isTrue(b, (String) null);
    }

    public static void isFalse(boolean b, RuntimeException e) {
        if (b == false) {
            return;
        }
        if (e == null) {
            e = new AssertException("必须是FALSE。");
        }
        throw e;
    }

    public static void isFalse(boolean b, String message) {
        isFalse(b, new AssertException(message));
    }

    public static void isFalse(boolean b) {
        isFalse(b, (String) null);
    }
}
